package com.cuijq.counter;

import com.cuijq.counter.controller.MetricsCollector;
import com.cuijq.counter.entity.RequestInfo;
import com.cuijq.counter.reporter.ConsoleReporter;
import com.cuijq.counter.reporter.EmailReporter;
import com.cuijq.counter.service.MetricsStorage;
import com.cuijq.counter.service.impl.RedisMetricsStorage;

/**
 * @Classname Demo
 * @Description TODO
 * @Date 2021/4/30 13:51
 * @Created by CuiJQ
 */
public class Demo {

  public static void main(String[] args) {
    MetricsStorage storage = new RedisMetricsStorage();
    ConsoleReporter consoleReporter = new ConsoleReporter(storage);
    consoleReporter.startRepeatedReport(60, 60);
    EmailReporter emailReporter = new EmailReporter(storage);
    emailReporter.addToAddress("wangzheng@xzg.com");
    emailReporter.startDailyReport();
    MetricsCollector collector = new MetricsCollector(storage);
    collector.recordRequest(new RequestInfo("register", 123, 10234));
    collector.recordRequest(new RequestInfo("register", 223, 11234));
    collector.recordRequest(new RequestInfo("register", 323, 12334));
    collector.recordRequest(new RequestInfo("login", 23, 12434));
    collector.recordRequest(new RequestInfo("login", 1223, 14234));
    try {
      Thread.sleep(100000);
    } catch (InterruptedException e) {
      e.printStackTrace();
    }
  }
}
